package code.example.javassist.reflect;

import java.beans.BeanInfo;
import java.beans.PropertyDescriptor;

public class PropertiesReflector {
    BeanInfo beanInfo = null;
    PropertyDescriptor pds []  = null;
    public PropertiesReflector(BeanInfo beanInfo){
        this.beanInfo = beanInfo;
    }
    public PropertyReflector createPropertyReflector(String propertyName){
        if ( pds == null) {
            pds = beanInfo.getPropertyDescriptors();
        }
        for(int i=0;i<pds.length;i++){
            if(pds[i].getName().equals(propertyName)){
                return new PropertyReflector(pds[i]);
            }
        }
        throw new RuntimeException("no property named "+propertyName);
    }
}
